home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / answers / msdos-programmer-faq / part3 < prev    next >
Encoding:
Text File  |  1993-06-26  |  46.2 KB  |  1,015 lines

  1. Newsgroups: comp.os.msdos.programmer,comp.answers,news.answers
  2. Path: senator-bedfellow.mit.edu!enterpoop.mit.edu!usc!math.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!ncoast!brown
  3. From: brown@NCoast.ORG (Stan Brown)
  4. Subject: comp.os.msdos.programmer FAQ part 3 of 4
  5. Expires: Fri, 23 Jul 1993 23:18:30 GMT
  6. Organization: Oak Road Systems, Cleveland Ohio USA
  7. Distribution: world
  8. Date: Sat, 26 Jun 1993 23:18:30 GMT
  9. Approved: news-answers-request@MIT.Edu
  10. Message-ID: <msdos-faq.9311.3@NCoast.ORG>
  11. Followup-To: comp.os.msdos.programmer
  12. Keywords: 
  13. References: <msdos-faq.9311.2@NCoast.ORG>
  14. Supersedes: <msdos-faq.9310.3@NCoast.ORG>
  15. Lines: 997
  16. Xref: senator-bedfellow.mit.edu comp.os.msdos.programmer:24752 comp.answers:1134 news.answers:9758
  17.  
  18.  
  19. Archive-name: msdos-programmer-faq/part3
  20. Last-modified: 26 June 1993
  21.  
  22.  
  23. (continued from part 2)         (no warranty on the code or information)
  24.  
  25. If the posting date is more than six weeks in the past, see instructions
  26. in part 4 of this list for how to get an updated copy.
  27.  
  28. Copyright (C) 1993  Stan Brown, Oak Road Systems.  All rights reserved.
  29.  
  30.  
  31. section 4.  Disks and files
  32. ===========================
  33.  
  34. Q401. What drive was the PC booted from?
  35.  
  36.     Under DOS 4.0 or later, load 3305 hex into AX; do an INT 21.  DL is
  37.     returned with an integer indicating the boot drive (1=A:, etc.).
  38.  
  39. Q402. How can I boot from drive b:?
  40.  
  41.     (rev: 18 Apr 1993)  Downloadable shareware:
  42.         pd1:<msdos.dskutl>boot_b.zip from Simtel
  43.         /pc/bootutil/boot_b.zip from garbo.
  44.     The included documentation says it works by writing a new boot
  45.     sector on a disk in your a: drive that redirects the boot to your
  46.     b: drive.
  47.  
  48.     If that doesn't work, you can always interchange your a: and b:
  49.     drives by switching ribbon cables and changing the setup in your
  50.     BIOS.  From an article posted 27 Jan 1993 on another newsgroup:
  51.  
  52.     Take the "ribbon" connector, as you call it, and switch them.  To
  53.     double check, start at the end of the cable that connects to the
  54.     motherboard or floppy controller.  Follow the cable until you get to
  55.     the first connector.  Connect this to the drive you want to be b:.
  56.     After this, there should be a few lines on the cable that get
  57.     flipped left to right.  (On most cables, they just cut the lines and
  58.     physically reverse them.  It should be quite obvious from looking at
  59.     the cable.)  Anyway, the connector after the pins get flipped
  60.     right to left is the connector for your a: drive.
  61.  
  62. Q403. Which real and virtual disk drives are valid?
  63.  
  64.     Use INT 21 function 29 (parse filename).  Point DS:SI at a null-
  65.     terminated ASCII string that contains the drive letter and a colon,
  66.     point ES:DI at a 37-byte dummy FCB buffer, set AX to 2900h, and do
  67.     an INT 21.  On return, AL is FF if the drive is invalid, something
  68.     else if the drive is valid.  RAM disks and SUBSTed drives are
  69.     considered valid.
  70.  
  71.     Unfortunately, the b: drive is considered valid even on a single-
  72.     diskette system.  You can check that special case by interrogating
  73.     the BIOS equipment byte at 0040:0010.  Bits 7-6 contain the one less
  74.     than the number of diskette drives, so if those bits are zero you
  75.     know that b: is an invalid drive even though function 29 says it's
  76.     valid.
  77.  
  78.     Following is some code originally posted by Doug Dougherty, with my
  79.     fix for the b: special case, tested only in Borland C++ 2.0 (in
  80.     the small model):
  81.  
  82.         #include <dos.h>
  83.         void drvlist(void)  {
  84.             char *s = "A:", fcb_buff[37];
  85.             int valid;
  86.             for (   ;  *s<='Z';  (*s)++) {
  87.                 _SI = (unsigned) s;
  88.                 _DI = (unsigned) fcb_buff;
  89.                 _ES = _DS;
  90.                 _AX = 0x2900;
  91.                 geninterrupt(0x21);
  92.                 valid = _AL != 0xFF;
  93.                 if (*s == 'B'  &&  valid) {
  94.                     char far *equipbyte = (char far *)0x00400010UL;
  95.                     valid = (*equipbyte & (3 << 6)) != 0;
  96.                 }
  97.                 printf("Drive '%s' is %sa valid drive.\n",
  98.                         s, valid ? "" : "not ");
  99.             }
  100.         }
  101.  
  102. Q404. How can I make my single floppy drive both a: and b:?
  103.  
  104.     Under any DOS since DOS 2.0, you can put the command
  105.  
  106.         assign b=a
  107.  
  108.     into your AUTOEXEC.BAT file.  Then, when you type "DIR B:" you'll no
  109.     longer get the annoying prompt to insert diskette B (and the even
  110.     more annoying prompt to insert A the next time you type "DIR A:").
  111.  
  112.     You may be wondering why anybody would want to do this.  Suppose you
  113.     use two different machines, maybe one at home and one at work.  One
  114.     of them has only a 3.5" diskette drive; the other machine has two
  115.     drives, and b: is the 3.5" one.  You're bound to type "dir b:" on
  116.     the first one, and get the nuisance message
  117.  
  118.         Insert diskette for drive B: and press any key when ready.
  119.  
  120.     But if you assign drive b: to point to a:, you avoid this problem.
  121.  
  122.     Caution:  there are a few commands, such as DISKCOPY, that will not
  123.     work right on ASSIGNed or SUBSTed drives.  See the DOS manual for
  124.     the full list.  Before typing one of those commands, be sure to turn
  125.     off the mapping by typing "assign" without arguments.
  126.  
  127.     The DOS 5.0 manual says that ASSIGN is obsolete, and recommends the
  128.     equivalent form of SUBST: "subst b: a:\".  Unfortunately, if this
  129.     command is executed when a: doesn't hold a diskette, the command
  130.     fails.  ASSIGN doesn't have this problem, so I must advise you to
  131.     disregard that particular bit of advice in the DOS manual.
  132.  
  133. Q405. Why won't my C program open a file with a path?
  134.  
  135.     You've probably got something like the following code:
  136.  
  137.         char *filename = "c:\foo\bar\mumble.dat";
  138.         . . .  fopen(filename, "r");
  139.  
  140.     The problem is that \f is a form feed, \b is a backspace, and \m is
  141.     m.  Whenever you want a backslash in a string constant in C, you
  142.     must use two backslashes:
  143.  
  144.         char *filename = "c:\\foo\\bar\\mumble.dat";
  145.  
  146.     This is a feature of every C compiler, because Dennis Ritchie
  147.     designed C this way.  It's a problem only on MS-DOS systems, because
  148.     only DOS (and Atari ST/TT running TOS, I'm told) uses the backslash
  149.     in directory paths.  But even in DOS this backslash convention
  150.     applies _only_ to string constants in your source code.  For file
  151.     and keyboard input at run time, \ is just a normal character, so
  152.     users of your program would type in file specs at run time the same
  153.     way as in DOS commands, with single backslashes.
  154.  
  155.     Another possibility is to code all paths in source programs with /
  156.     rather than \ characters:
  157.  
  158.         char *filename = "c:/foo/bar/mumble.dat";
  159.  
  160.     Ralf Brown writes that "All versions of the DOS kernel accept either
  161.     forward or backslashes as directory separators.  I tend to use this
  162.     form more frequently than backslashes since it is easier to type and
  163.     read."  This applies to DOS function calls (and therefore to calls
  164.     to the file library of every programming language), but not to DOS
  165.     commands.
  166.  
  167. Q406. How can I redirect printer output to a file?
  168.  
  169.     (rev: 18 Apr 1993)  My personal favorite utility for this purpose is
  170.     PRN2FILE from {PC Magazine}, downloadable as:
  171.         pd1:<msdos.printer>prn2file.arc at Simtel
  172.         /pc/printer/prn2file.zip at garbo.
  173.     {PC Magazine} has given copies away as part of its utilities disks,
  174.     so you may already have a copy.
  175.  
  176.     The directories mentioned above have lots of other utilities to
  177.     redirect printer output.
  178.  
  179. Q407. How can I redirect the output of a batch file?
  180.  
  181.     (new: 12 June 1993) Assuming the batch file is called batch.bat, to
  182.     send its output (stdout) to another file, just invoke COMMAND.COM as
  183.     a secondary command processor:
  184.  
  185.         command /c batch parameters_if_any >outfile
  186.  
  187.     Timo Salmi's notes on this and other batch tricks are downloadable:
  188.         pd1:<msdos.batutl>tsbat43.zip at Simtel
  189.         /pc/ts/tsbat43.zip at garbo.
  190.  
  191. Q408. How can my program open more files than DOS's limit of 20?
  192.  
  193.     (rev: 1 May 1993.  This is a summary of an article Ralf Brown posted
  194.     on 8 August 1992, with some additions from a Microsoft tech note.)
  195.  
  196.     There are separate limits on files and file handles.  For example,
  197.     DOS opens three files but five file handles:  CON (stdin, stdout,
  198.     and stderr), AUX (stdaux), and PRN (stdprn).
  199.  
  200.     The limit in FILES= in CONFIG.SYS is a system-wide limit on files
  201.     opened by all programs (including the three that DOS opens and any
  202.     opened by TSRs); each process has a limit of 20 handles (including
  203.     the five that DOS opens).  Example:  CONFIG.SYS has FILES=40.  Then
  204.     program #1 will be able to open 15 file handles.  Assuming that the
  205.     program actually does open 15 handles pointing to 15 different
  206.     files, other programs could still open a total of 22 files (40-3-15
  207.     = 22), though no one program could open more than 15 file handles.
  208.  
  209.     If you're running DOS 3.3 or later, you can increase the per-process
  210.     limit of 20 file handles by a call to INT 21 function 67, Set Handle
  211.     Count.  Your program is still limited by the system-wide limit on
  212.     open files, so you may also need to increase the FILES= value in
  213.     your CONFIG.SYS file (and reboot).  The run-time library that you're
  214.     using may have a fixed-size table of file handles, so you may also
  215.     need to get source code for the module that contains the table,
  216.     increase the table size, and recompile it.
  217.  
  218.     In Microsoft C the run-time library limits you to 20 file handles.
  219.     To change this, you must be aware of two limits:
  220.  
  221.     - file handles used with _open( ), _read( ), etc.: Edit _NFILE_ in
  222.       CRT0DAT.ASM.
  223.  
  224.     - stream files used with fopen( ), fread( ), etc.: Edit _NFILE_ in
  225.       _FILE.C for DOS or FILE.ASM for Windows/QuickWin.  This must not
  226.       exceed the value of _NFILE_ in CRT0DAT.ASM.
  227.  
  228.     (QuickWin uses the constant _WFILE_ in CRT0DAT.ASM and WFILE.ASM for
  229.     the maximum number of child text windows.)
  230.  
  231.     After changing the limits, recompile using CSTARTUP.BAT.  Microsoft
  232.     recommends that you first read README.TXT in the same directory.
  233.  
  234. Q409. How can I read, create, change, or delete the volume label?
  235.  
  236.     In DOS 5.0 (and, I believe, in 4.0 as well), there are actually two
  237.     volume labels: one, the traditional one, is an entry in the root
  238.     directory of the disk; and the other is in the boot record along
  239.     with the serial number (see next Q).  The DIR and VOL commands
  240.     report the traditional label; the LABEL command reports the
  241.     traditional one but changes both of them.
  242.  
  243.     In DOS 4.0 and later, use INT 21 function 69 to access the boot
  244.     record's serial number and volume label together; see the next Q.
  245.  
  246.     Assume that by "volume label" you mean the traditional one, the one
  247.     that DIR and VOL display.  Though it's a directory entry in the root
  248.     directory, you can't change it using the newer DOS file-access
  249.     functions (3C, 41, 43); instead, use the old FCB-oriented directory
  250.     functions.  Specifically, you need to allocate a 64-byte buffer and
  251.     a 41- byte extended FCB (file control block).  Call INT 21 AH=1A to
  252.     find out whether there is a volume label.  If there is, AL returns 0
  253.     and you can change the label using DOS function 17 or delete it
  254.     using DOS function 13.  If there's no volume label, function 1A will
  255.     return FF and you can create a label via function 16.  Important
  256.     points to notice are that ? wildcards are allowed but * are not; the
  257.     volume label must be space filled not null terminated.
  258.  
  259.     The following MSC 7.0 code worked for me in DOS 5.0; the functions
  260.     it uses have been around since DOS 2.0.  The function parameter is 0
  261.     for the current disk, 1 for a:, 2 for b:, etc.  It doesn't matter
  262.     what your current directory is; these functions always search the
  263.     root directory for volume labels.  (I didn't try to change the
  264.     volume label of any networked drives.)
  265.  
  266.     // Requires DOS.H, STDIO.H, STRING.H
  267.     void vollabel(unsigned char drivenum) {
  268.         static unsigned char extfcb[41], dta[64], status, *newlabel;
  269.         int chars_got = 0;
  270.         #define DOS(buff,func) __asm { __asm mov dx,offset buff \
  271.             __asm mov ax,seg buff  __asm push ds  __asm mov ds,ax \
  272.             __asm mov ah,func  __asm int 21h  __asm pop ds \
  273.             __asm mov status,al }
  274.         #define getlabel(buff,prompt) newlabel = buff;  \
  275.             memset(newlabel,' ',11);  printf(prompt);   \
  276.             scanf("%11[^\n]%n", newlabel, &chars_got);  \
  277.             if (chars_got < 11) newlabel[chars_got] = ' ';
  278.  
  279.         // Set up the 64-byte transfer area used by function 1A.
  280.         DOS(dta, 1Ah)
  281.         // Set up an extended FCB and search for the volume label.
  282.         memset(extfcb, 0, sizeof extfcb);
  283.         extfcb[0] = 0xFF;             // denotes extended FCB
  284.         extfcb[6] = 8;                // volume-label attribute bit
  285.         extfcb[7] = drivenum;         // 1=A, 2=B, etc.; 0=current drive
  286.         memset(&extfcb[8], '?', 11);  // wildcard *.*
  287.         DOS(extfcb,11h)
  288.         if (status == 0) {            // DTA contains volume label's FCB
  289.             printf("volume label is %11.11s\n", &dta[8]);
  290.             getlabel(&dta[0x18], "new label (\"delete\" to delete): ");
  291.             if (chars_got == 0)
  292.                 printf("label not changed\n");
  293.             else if (strncmp(newlabel,"delete     ",11) == 0) {
  294.                 DOS(dta,13h)
  295.                 printf(status ? "label failed\n" : "label deleted\n");
  296.             }
  297.             else {                    // user wants to change label
  298.                 DOS(dta,17h)
  299.                 printf(status ? "label failed\n" : "label changed\n");
  300.             }
  301.         }
  302.         else {                        // no volume label was found
  303.             printf("disk has no volume label.\n");
  304.             getlabel(&extfcb[8], "new label (<Enter> for none): ");
  305.             if (chars_got > 0) {
  306.                 DOS(extfcb,16h)
  307.                 printf(status ? "label failed\n" : "label created\n");
  308.             }
  309.         }
  310.     }   // end function vollabel
  311.  
  312. Q410. How can I get the disk serial number?
  313.  
  314.     Use INT 21.  AX=6900 gets the serial number; AX=6901 sets it.  See
  315.     Ralf Brown's interrupt list, or page 496 of {PC Magazine} July 1992,
  316.     for details.
  317.  
  318.     This function also gets and sets the volume label, but it's the
  319.     volume label in the boot record, not the volume label that a DIR
  320.     command displays.  See the preceding Q.
  321.  
  322. Q411. What's the format of .OBJ, .EXE., .COM files?
  323.  
  324.     Please see section 2, "Compile and link".
  325.  
  326. Q412. How can I flush the software disk cache?
  327.  
  328.     Please see "How can a program reboot my PC?" in section 7, "Other
  329.     software questions and problems".
  330.  
  331. section 5. Serial ports (COM ports)
  332. ===================================
  333.  
  334. Q501. How do I set my machine up to use COM3 and COM4?
  335.  
  336.     Unless your machine is fairly old, it's probably already set up.
  337.     After installing the board that contains the extra COM port(s),
  338.     check the I/O addresses in word 0040:0004 or 0040:0006.  (In DEBUG,
  339.     type "D 40:4 L4" and remember that every word is displayed low
  340.     byte first, so if you see "03 56" the word is 5603.)  If those
  341.     addresses are nonzero, your PC is ready to use the ports and you
  342.     don't need the rest of this answer.
  343.  
  344.     If the I/O address words in the 0040 segment are zero after you've
  345.     installed the I/O board, you need some code to store these values
  346.     into the BIOS data segment:
  347.  
  348.         0040:0004  word  I/O address of COM3
  349.         0040:0006  word  I/O address of COM4
  350.         0040:0011  byte (bits 3-1): number of serial ports installed
  351.  
  352.     The documentation with your I/O board should tell you the port
  353.     addresses.  When you know the proper port addresses, you can add
  354.     code to your program to store them and the number of serial ports
  355.     into the BIOS data area before you open communications.  Or you can
  356.     use DEBUG to create a little program to include in your AUTOEXEC.BAT
  357.     file, using this script:
  358.  
  359.             n SET_ADDR.COM      <--- or a different name ending in .COM
  360.             a 100
  361.             mov  AX,0040
  362.             mov  DS,AX
  363.             mov  wo [0004],aaaa <--- replace aaaa with COM3 address or 0
  364.             mov  wo [0006],ffff <--- replace ffff with COM4 address or 0
  365.             and  by [0011],f1
  366.             or   by [0011],8    <--- use number of serial ports times 2
  367.             mov  AH,0
  368.             int  21
  369.                                 <--- this line must be blank
  370.             rCX
  371.             1f
  372.             rBX
  373.             0
  374.             w
  375.             q
  376.  
  377. Q502. How do I find the I/O address of a COM port?
  378.  
  379.     Look in the four words beginning at 0040:0000 for COM1 through COM4.
  380.     (The DEBUG command "D 40:0 L8" will do this.  Remember that words
  381.     are stored and displayed low byte first, so a word value of 03F8
  382.     will be displayed as F8 03.)  If the value is zero, that COM port is
  383.     not installed (or you've got an old BIOS; see the preceding Q).  If
  384.     the value is nonzero, it is the I/O address of the transmit/receive
  385.     register for the COM port.  Each COM port occupies eight consecutive
  386.     I/O addresses (though only seven are used by many chips).
  387.  
  388.     Here's some C code to find the I/O address:
  389.  
  390.         unsigned ptSel(unsigned comport) {
  391.             unsigned io_addr;
  392.             if (comport >= 1  &&  comport <= 4) {
  393.                 unsigned far *com_addr = (unsigned far *)0x00400000UL;
  394.                 io_addr = com_addr[comport-1];
  395.             }
  396.             else
  397.                 io_addr = 0;
  398.             return io_addr;
  399.         }
  400.  
  401. Q503. But aren't the COM ports always at I/O addresses 3F8, 2F8, 3E8,
  402.       and 2E8?
  403.  
  404.     The first two are usually right (though not always); the last two
  405.     are different on many machines.
  406.  
  407. Q504. How do I configure a COM port and use it to transmit data?
  408.  
  409.     (rev: 18 Apr 1993) Do you want actual code, or do you want books
  410.     that explain what's going on?
  411.  
  412.     1) Source code
  413.  
  414.     First, check your compiler's run-time library.  Many compilers offer
  415.     functions similar to Microsoft C's _bios_serialcom() or Borland's
  416.     bioscom(), which may meet your needs.
  417.  
  418.     Second, check for downloadable resources at Simtel and garbo.  At
  419.     Simtel, pd1:<msdos.c>pcl4c34.zip (March 1993) is described as
  420.     "Asynchronous communications library for C"; garbo has a whole
  421.     /pc/comm directory.  Also, an extended example is in Borland's
  422.     TechFax TI445, downloadable as part of
  423.         pd1:<msdos.turbo-c>bchelp10.zip at Simtel
  424.         /pc/turbopas/bchelp10.zip at garbo.
  425.     Though written by Borland, much of it is applicable to other forms
  426.     of C, and it should give you ideas for other programming languages.
  427.  
  428.     2) Reference books
  429.  
  430.     After hearing several recommendations, I looked at Joe Campbell's {C
  431.     Programmer's Guide to Serial Communications}, ISBN 0-672-22584-0,
  432.     and agree that it is excellent.  He gives complete details on how
  433.     serial ports work, along with complete programs for doing polled or
  434.     interrupt-driver I/O.  The book is quite thick, and none of it looks
  435.     like filler.
  436.  
  437.     If Campbell's book is overkill for you, you'll find a good short
  438.     description of serial I/O in {DOS 5: A Developer's Guide}, ISBN
  439.     1-55851-177-6, by Al Williams.
  440.  
  441. section 6. Other hardware questions and problems
  442. ================================================
  443.  
  444. Q601. Which 80x86 CPU is running my program?
  445.  
  446.     (rev: 20 June 1993)  According to an article posted by Michael
  447.     Davidson, Intel's approved code for distinguishing among 8086,
  448.     80286, 80386, and 80486 and for detecting the presence of an 80287
  449.     or 80387 is published in Intel's 486SX processor manual (order
  450.     number 240950-001).  David Kirschbaum's improved version of this is
  451.     downloadable as
  452.         pd1:<msdos.sysutl>cpuid593.zip from Simtel
  453.         /pc/sysinfo/cpuid593.zip from garbo.
  454.  
  455.     According to an article posted by its author, WCPU knows the
  456.     differences between DX and SX varieties of 386 and 486 chips, and
  457.     can detect a math coprocessor and a Pentium.  It's downloadable as
  458.         pd1:<msdos.sysutl>wcpu050.zip at Simtel
  459.         /pc/sysinfo/wcpu050.zip at garbo.
  460.  
  461. Q602. How can a C program send control codes to my printer?
  462.  
  463.     If you just fprintf(stdprn, ...), C will translate some of your
  464.     control codes.  The way around this is to reopen the printer in
  465.     binary mode:
  466.  
  467.         prn = fopen("PRN", "wb");
  468.  
  469.     You must use a different file handle because stdprn isn't an lvalue.
  470.     By the way, PRN or LPT1 must not be followed by a colon in DOS 5.0.
  471.  
  472.     There's one special case, Ctrl-Z (ASCII 26), the DOS end-of-file
  473.     character.  If you try to send an ASCII 26 to your printer, DOS
  474.     simply ignores it.  To get around this, you need to reset the
  475.     printer from "cooked" to "raw" mode.  Microsoft C users must use int
  476.     21 function 44, "get/set device information".  Turbo C and Borland
  477.     C++ users can use ioctl to accomplish the same thing:
  478.  
  479.         ioctl(fileno(prn), 1, ioctl(fileno(prn),0) & 0xFF | 0x20, 0);
  480.  
  481.     An alternative approach is simply to write the printer output into a
  482.     disk file, then copy the file to the printer with the /B switch.
  483.  
  484.     A third approach is to bypass DOS functions entirely and use the
  485.     BIOS printer functions at INT 17.  If you also fprintf(stdprn,...)
  486.     in the same program, you'll need to use fflush( ) to synchronize
  487.     fprintf( )'s buffered output with the BIOS's unbuffered.
  488.  
  489.     By the way, if you've opened the printer in binary mode from a C
  490.     program, remember that outgoing \n won't be translated to carriage
  491.     return/line feed.  Depending on your printer, you may need to send
  492.     explicit \n\r sequences.
  493.  
  494. Q603. How can I redirect printer output to a file?
  495.  
  496.     Please see section 4, "Disks and files", for the answer.
  497.  
  498. Q604. Which video adapter is installed?
  499.  
  500.     The technique below should work if your BIOS is not too old.  It
  501.     uses three functions from INT 10, the BIOS video interrupt.  (If
  502.     you're using a Borland language, you may not have to do this the
  503.     hard way.  Look for a function called DetectGraph or something
  504.     similar.)
  505.  
  506.     Set AH=12h, AL=0, BL=32h; INT 10h.  If AL is 12h, you have a VGA.
  507.     If not, set AH=12h, BL=10h; INT 10h.  If BL is 0,1,2,3, you have an
  508.     EGA with 64,128,192,256K memory.  If not, set AH=0Fh; INT 10h.  If
  509.     AL is 7, you have an MDA (original monochrome adapter) or Hercules;
  510.     if not, you have a CGA.
  511.  
  512.     I've tested this for my VGA and got the right answer; but I can't
  513.     test it for the other equipment types.  Please let me know by email
  514.     at brown@ncoast.org if your results vary.
  515.  
  516. Q605. How do I switch to 43- or 50-line mode?
  517.  
  518.     pd1:<msdos.screen>vidmode.zip, downloadable from Simtel, contains
  519.     .COM utilities and .ASM source code.
  520.  
  521. Q606. How can I find the Microsoft mouse position and button status?
  522.  
  523.     Use INT 33 function 3, described in Ralf Brown's interrupt list.
  524.  
  525.     The Windows manual says that the Logitech mouse is compatible with
  526.     the Microsoft one, so I assume the interrupt will work the same.
  527.  
  528.     Also, many files are downloadable from pd1:<msdos.mouse> at Simtel.
  529.  
  530. Q607. How can I access a specific address in the PC's memory?
  531.  
  532.     First check the library that came with your compiler.  Many vendors
  533.     have some variant of peek and poke functions; in Turbo Pascal use
  534.     the pseudo-arrays Mem, MemW, and MemL.  As an alternative, you can
  535.     construct a far pointer:  use Ptr in Turbo Pascal, MK_FP in the
  536.     Turbo C family, and FP_OFF and FP_SEG in Microsoft C.
  537.  
  538.     Caution:  Turbo C and Turbo C++ also have FP_OFF and FP_SEG macros,
  539.     but they can't be used to construct a pointer.  In Borland C++ those
  540.     macros work the same as in Microsoft C, but MK_FP is easier to use.
  541.  
  542.     By the way, it's not useful to talk about "portable" ways to do
  543.     this.  Any operation that is tied to a specific memory address is
  544.     not likely to work on another kind of machine.
  545.  
  546. Q608. How can I read or write my PC's CMOS memory?
  547.  
  548.     (rev: 13 Jun 1993) There are a great many public-domain utilities
  549.     that do this.  These are downloadable from Simtel:
  550.  
  551.     pd1:<msdos.at>
  552.     cmos14.zip     5965  920817  Saves/restores CMOS to/from file
  553.     cmoser11.zip  28323  910721  386/286 enhanced CMOS setup program
  554.     cmosram.zip   76096  920214  Save AT/386/486 CMOS data to file and restore
  555.     rom2.zip      15692  900131  Save AT and 386 CMOS data to file and restore
  556.     setup21.zip   18172  880613  Setup program which modifies CMOS RAM
  557.     viewcmos.zip  11068  900225  Display contents of AT CMOS RAM, w/C source
  558.  
  559.     Downloadable from garbo, /pc/ts/tsutle22.zip contains a CMOS program
  560.     to check and display CMOS memory, but not to write to it.
  561.  
  562.     I have heard good reports of CMOS299.ZIP, available in the pc.dir
  563.     directory of cantva.canterbury.ac.nz [132.181.30.3].
  564.  
  565.     Of the above, my only experience is with CMOSRAM, which seems to
  566.     work fine.  It contains an excellent (and witty) .DOC file that
  567.     explains the hardware involved and gives specific recommendations
  568.     for preventing disaster or recovering from it.  It's $5 shareware.
  569.  
  570.     Robert Jourdain's {Programmer's Problem Solver for the IBM PC, XT,
  571.     and AT} has code for accessing the CMOS RAM, according to an article
  572.     posted in this newsgroup.
  573.  
  574. Q609. How can I access memory beyond 640K?
  575.  
  576.     (rev: 2 May 1993) This is a legitimate FAQ, in that it is frequently
  577.     asked.  But there is no single agreed-upon answer.  Please see the
  578.     separate article called "How to access memory above 640K" in
  579.     comp.os.msdos.programmer and in faqp*.zip at Simtel and garbo.
  580.  
  581. Q610. Where can I find a list of 80x86 opcodes?
  582.  
  583.     (new: 2 May 1993)  It's part of a rather long file, the 8 Dec 1992
  584.     edition of the Info-IBMPC Digest (V92 #185), downloadable as
  585.     pd2:<archives.ibmpc>9212.1-txt at Simtel.  (Note: pd2, not
  586.     pd1.)  Opcodes for the 8086 through 80386 are listed.
  587.  
  588. section 7. Other software questions and problems
  589. ================================================
  590.  
  591. Q701. How can a program reboot my PC?
  592.  
  593.     You can generate a "cold" boot or a "warm" boot.  A cold boot is
  594.     the same as turning the power off and on; a warm boot is the same as
  595.     Ctrl-Alt-Del and skips the power-on self test.
  596.  
  597.     For a warm boot, store the hex value 1234 in the word at 0040:0072.
  598.     For a cold boot, store 0 in that word.  Then, if you want to live
  599.     dangerously, jump to address FFFF:0000.  Here's C code to do it:
  600.  
  601.         /* WARNING:  data loss possible */
  602.         void bootme(int want_warm)  /* arg 0 = cold boot, 1 = warm */ {
  603.             void (far* boot)(void) = (void (far*)(void))0xFFFF0000UL;
  604.             unsigned far* type = (unsigned far*)0x00400072UL;
  605.             *type = (want_warm ? 0x1234 : 0);
  606.             (*boot)( );
  607.         }
  608.  
  609.     What's wrong with that method?  It will boot right away, without
  610.     closing files, flushing disk caches, etc.  If you boot without
  611.     flushing a write-behind disk cache (if one is running), you could
  612.     lose data or even trash your hard drive.
  613.  
  614.     There are two methods of signaling the cache to flush its buffers:
  615.     (1) simulate a keyboard Ctrl-Alt-Del in the keystroke translation
  616.     function of the BIOS (INT 15 function 4F), and (2) issue a disk
  617.     reset (DOS function 0D).  Most disk-cache programs hook one or both
  618.     of those interrupts, so if you use both methods you'll probably be
  619.     safe.
  620.  
  621.     When user code simulates a Ctrl-Alt-Del, one or more of the programs
  622.     that have hooked INT 15 function 4F can ask that the key be ignored by
  623.     clearing the carry flag.  For example, HyperDisk does this when it
  624.     has started but not finished a cache flush.  So if the carry flag
  625.     comes back cleared, the boot code has to wait a couple of clock
  626.     ticks and then try again.  (None of this matters on older machines
  627.     whose BIOS can't support 101- or 102-key keyboards; see "What is the
  628.     SysRq key for?" in section 3, "Keyboard".)
  629.  
  630.     Here's C code that tries to signal the disk cache (if any) to flush:
  631.  
  632.         #include <dos.h>
  633.         void bootme(int want_warm)  /* arg 0 = cold boot, 1 = warm */ {
  634.             union REGS reg;
  635.             void    (far* boot)(void) = (void (far*)(void))0xFFFF0000UL;
  636.             unsigned far* boottype    =     (unsigned far*)0x00400072UL;
  637.             char     far* shiftstate  =         (char far*)0x00400017UL;
  638.             unsigned      ticks;
  639.             int           time_to_waste;
  640.             /* Simulate reception of Ctrl-Alt-Del: */
  641.             for (;;) {
  642.                 *shiftstate |= 0x0C;    /* turn on Ctrl & Alt */
  643.                 reg.x.ax = 0x4F53;      /* 0x53 = Del's scan code */
  644.                 reg.x.cflag = 1;        /* sentinel for ignoring key */
  645.                 int86(0x15, ®, ®);
  646.                 /* If carry flag is still set, we've finished. */
  647.                 if (reg.x.cflag)
  648.                     break;
  649.                 /* Else waste some time before trying again: */
  650.                 reg.h.ah = 0;
  651.                 int86(0x1A, ®, ®);/* system time into CX:DX */
  652.                 ticks = reg.x.dx;
  653.                 for (time_to_waste = 3;  time_to_waste > 0;  ) {
  654.                     reg.h.ah = 0;
  655.                     int86(0x1A, ®, ®);
  656.                     if (ticks != reg.x.dx)
  657.                         ticks = reg.x.dx , --time_to_waste;
  658.                 }
  659.             }
  660.             /* Issue a DOS disk reset request: */
  661.             reg.h.ah = 0x0D;
  662.             int86(0x21, ®, ®);
  663.             /* Set boot type and boot: */
  664.             *boottype = (want_warm ? 0x1234 : 0);
  665.             (*boot)( );
  666.         }
  667.  
  668. Q702. How can I time events with finer resolution than the system
  669.       clock's 55 ms (about 18 ticks a second)?
  670.  
  671.     (rev: 20 June 1993) The following files, among others, are
  672.     downloadable from Simtel:
  673.  
  674.     pd1:<msdos.at>
  675.     atim.zip       4783  881126  Precision program timing for AT
  676.  
  677.     pd1:<msdos.c>
  678.     millisec.zip  37734  911205  MSC/asm src for millisecond res timing
  679.     mschrt3.zip   53708  910605  High-res timer toolbox for MSC 5.1
  680.     msec_12.zip    8484  920320  High-def millisec timer v1.2 (C,ASM)
  681.     ztimer11.zip  77625  920428  Microsecond timer for C, C++, ASM
  682.         (also at garbo as /pc/c/ztimer11.zip)
  683.  
  684.     pd1:<msdos.turbo-c>
  685.     tchrt3.zip    53436  910606  High-res timer toolbox for Turbo C 2.0
  686.     tctimer.arc   20087  891030  High-res timing of events for Turbo C
  687.         (same as /pc/c/tctimer.zoo at garbo; both are version 1.0)
  688.  
  689.     For Turbo Pascal users, source and object code are downloadable in
  690.         pd1:<msdos.turbopas>bonus507.zip at Simtel
  691.         /pc/turbopas/bonus507.zip at garbo.
  692.  
  693. Q703. How can I find the error level of the previous program?
  694.  
  695.     (rev: 20 June 1993)  First, which previous program are you talking
  696.     about?  If your current program ran another one, when the child
  697.     program ends its error level is available to the program that
  698.     spawned it.  Most high-level languages provide a way to do this; for
  699.     instance, in Turbo Pascal it's Lo(DosExitCode) and the high byte
  700.     gives the way in which the child terminated.  In Microsoft C, the
  701.     exit code of a synchronous child process is the return value of the
  702.     spawn-type function that creates the process.
  703.  
  704.     If your language doesn't have a function to return the error code
  705.     of a child process, you can use INT 21 function 4D (get return
  706.     code).  By the way, this will tell you the child's exit code and the
  707.     manner of its ending (normal, Ctrl-C, critical error, or TSR).
  708.  
  709.     It's much trickier if the current program wants to get the error
  710.     level of the program that ran and finished before this one started.
  711.     G.A.Theall has published source and compiled code to do this; the
  712.     code is downloadable as
  713.         pd1:<msdos.batutl>errlvl13.zip at Simtel
  714.         /pc/batchutil/errlvl13.zip at garbo.
  715.     (The code uses undocumented features in DOS 3.3 through 5.0.  Theall
  716.     says in the .DOC file that the values returned under 4DOS or other
  717.     replacements won't be right.)
  718.  
  719. Q704. How can a program set DOS environment variables?
  720.  
  721.     (rev: 13 June 1993)  Program functions that read or write "the
  722.     environment" typically access only the program's copy of it.  What
  723.     this Q really wants to do is to modify the active environment, the
  724.     one that is affected by SET commands in batch files or at the DOS
  725.     prompt.  You need to do some programming to find the active
  726.     environment, and that depends on the version of DOS.
  727.  
  728.     A fairly well-written article in {PC Magazine} 28 Nov 1989
  729.     (viii:20), pages 309-314, explains how to find the active
  730.     environment, and includes Pascal source code.  The article hints at
  731.     how to change the environment, and suggests creating paths longer
  732.     than 128 characters as one application.
  733.  
  734.     Now as for downloadable source code, there are many possibilities.
  735.     Of the ones I looked at (not all of them), I liked
  736.         pd1:<msdos.envutil>rbsetnv1.zip at Simtel
  737.         /pc/envutil/rbsetnv1.zip at garbo
  738.     the best.  It includes some utilities to manipulate the environment,
  739.     with source code in C.  A newer program is
  740.         pd1:<msdos.batutl>strings2.zip at Simtel
  741.         part of /pc/pcmag/vol11n22.zip at garbo,
  742.     which is the code from {PC Magazine} 22 Dec 1992 (xi:22).
  743.  
  744.     You can also use a call to INT 2E, Pass Command to Interpreter for
  745.     Execution; see Ralf Brown's interrupt list for details and cautions.
  746.  
  747. Q705. How can I change the switch character to - from /?
  748.  
  749.     Under DOS 5.0, you can't -- not completely, anyway.  INT 21 function
  750.     3700, get switch character, always returns a '/' (hex 2F) -- and the
  751.     DOS commands don't even call that function, but hard code '/' as the
  752.     switch character.
  753.  
  754.     Some history:  DOS used to let you change the switch character by
  755.     using SWITCHAR= in CONFIG.SYS or by calling DOS function 3701.  DOS
  756.     commands and other programs called DOS function 3700 to find out the
  757.     switch character.  If you changed the switch character to '-' (the
  758.     usual choice), you could then type "dir c:/c700 -p" rather than "dir
  759.     c:\c700 /p".  Under DOS 4.0, the DOS commands ignored the switch
  760.     character but functions 3700 and 3701 still worked and could be used
  761.     by other programs.  Under DOS 5.0, even those functions no longer
  762.     work, though all DOS functions still accept '/' or '\' in file
  763.     specs.
  764.  
  765.     You can reactivate the functions to get and set switchar by using
  766.     programs like SLASH.ZIP or the sample TSR called SWITCHAR in
  767.     amisl091.zip (see "How can I write a TSR?", below.)  DOS commands
  768.     will still use the slash, but non-DOS programs that call DOS func-
  769.     tion 3700 will use your desired switch character.  (DOS replacements
  770.     like 4DOS may honor the switch character for internal commands.)
  771.  
  772.     Some readers may wonder why this is even an issue.  Making '-' the
  773.     switch character frees up the front slash to separate names in the
  774.     path part of a file spec.  This is easier for the ten-fingered to
  775.     type, and it's one less difference to remember for commuters between
  776.     DOS and Unix.  The switch character is the only issue, since all the
  777.     INT 21 functions accept '/' or '\' to separate directory names.
  778.  
  779. Q706. Why does my interrupt function behave strangely?
  780.  
  781.     Interrupt service routines can be tricky, because you have to do
  782.     some things differently from "normal" programs.  If you make a
  783.     mistake, debugging is a pain because the symptoms may not point at
  784.     what's wrong.  Your machine may lock up or behave erratically, or
  785.     just about anything else can happen.  Here are some things to look
  786.     for.  (See the next Q for general help before you have a problem.)
  787.  
  788.     First, did you fail to set up the registers at the start of your
  789.     routine?  When your routine begins executing, you can count on
  790.     having CS point to your code segment and SS:SP point to some valid
  791.     stack (of unknown length), and that's it.  In particular, an
  792.     interrupt service routine must set DS to DGROUP before accessing any
  793.     data in its data segments.  (If you're writing in a high-level
  794.     language, the compiler may generate this code for you automatically;
  795.     check your compiler manual.  For instance, in Borland and Microsoft
  796.     C, give your function the "interrupt" attribute.)
  797.  
  798.     Did you remember to turn off stack checking when compiling your
  799.     interrupt server and any functions it calls?  The stack during the
  800.     interrupt is not where the stack-checking code expects it to be.
  801.     (Caution:  Some third-party libraries have stack checking compiled
  802.     in, so you can't call them from your interrupt service routine.)
  803.  
  804.     Next, are you calling any DOS functions (INT 21, 25, or 26) in your
  805.     routine?  DOS is not re-entrant.  This means that if your interrupt
  806.     happens to be triggered while the CPU is executing a DOS function,
  807.     calling another DOS function will wreak havoc.  (Some DOS functions
  808.     are fully re-entrant, as noted in Ralf Brown's interrupt list.
  809.     Also, your program can test, in a way too complicated to present
  810.     here, when it's safe to call non-re-entrant DOS functions.  See INT
  811.     28 and functions 34, 5D06, 5D0B of INT 21; and consult {Undocumented
  812.     DOS} by Andrew Schulman.  Your program must read both the "InDOS
  813.     flag" and the "critical error flag".)
  814.  
  815.     Is a function in your language library causing trouble?  Does it
  816.     depend on some initializations done at program startup that is no
  817.     longer available when the interrupt executes?  Does it call DOS (see
  818.     preceding paragraph)?  For example, in both Borland and Microsoft C
  819.     the memory-allocation functions (malloc, etc..) and standard I/O
  820.     functions (scanf, printf) call DOS functions and also depend on
  821.     setups that they can't get at from inside an interrupt.  Many other
  822.     library functions have the same problem, so you can't use them
  823.     inside an interrupt function without special precautions.
  824.  
  825.     Is your routine simply taking too long?  This can be a problem if
  826.     you're hooking on to the timer interrupt, INT 1C or INT 8.  Since
  827.     that interrupt expects to be called 18.2 times a second, your
  828.     routine -- plus any others hooked to the same interrupts -- must
  829.     execute in less than 55 ms.  If they use even a substantial fraction
  830.     of that time, you'll see significant slowdowns of your foreground
  831.     program.  A good discussion is downloadable as
  832.         pub/msdos/simtel20/info/INTSHARE at ni.funet.fi
  833.         pd1:<msdos.info>intshare at Simtel.
  834.  
  835.     Did you forget to restore all registers at the end of your routine?
  836.  
  837.     Did you chain improperly to the original interrupt?  You need to
  838.     restore the stack to the way it was upon entry to your routine, then
  839.     do a far jump (not call) to the original interrupt service routine.
  840.     (The process is a little different in high-level languages.)
  841.  
  842. Q707. How can I write a TSR (terminate-stay-resident utility)?
  843.  
  844.     (rev: 20 June 1993)  There are books, and there's code to download.
  845.  
  846.     First, the books:
  847.  
  848.     - Ray Duncan's {Advanced MS-DOS}, ISBN 1-55615-157-8, gives a brief
  849.       checklist intended for experienced programmers.  The ISBN is for
  850.       the second edition, through DOS 4; but check to see whether the
  851.       DOS 5 version is available yet.
  852.  
  853.     - {DOS 5:  A Developer's Guide} by Al Williams, ISBN 1-55851-177-6,
  854.       goes into a little more detail, 90 pages worth!
  855.  
  856.     - Pascal programmers might look at {The Ultimate DOS Programmer's
  857.       Manual} by John Mueller and Wallace Wang, ISBN 0-8306-3534-3, for
  858.       an extended example in mixed Pascal and assembler.
  859.  
  860.     - For a pure assembler treatment, check Steven Holzner's {Advanced
  861.       Assembly Language}, ISBN 0-13-663014-6.  He has a book with the
  862.       same title out from Brady Press, but it's about half as long as
  863.       this one.
  864.  
  865.     - For C programmers, there's a chapter in Herbert Schildt's {The Art
  866.       of C:  Elegant Programming Solutions}.  I haven't seen the book,
  867.       but a posted article recommended it.
  868.  
  869.     Next, the code.  Some of it is companion code to published articles,
  870.     which are also listed below:
  871.  
  872.     - The Alternate Multiplex Interrupt Specification, downloadable as
  873.         pd1:<msdos.info>altmpx35.zip at Simtel
  874.         /pc/programming/altmpx35.zip at garbo
  875.         /afs/cs/user/ralf/pub/altmpx35.zip at cs.cmu.edu
  876.  
  877.     - Ralf Brown's assembly-language implementation of the spec, with
  878.       utilities in C, downloadable as
  879.         pd1:<msdos.asmutl>amisl091.zip at Simtel
  880.         /pc/c/amisl091.zip at garbo
  881.         /afs/cs/user/ralf/pub/amisl091.zip at cs.cmu.edu
  882.  
  883.     - Douglas Boling's MASM template for a TSR is downloadable as
  884.         pd1:<msdos.asmutl>template.zip at Simtel.
  885.  
  886.     - A posted article mentions Boling's "Strategies and Techniques for
  887.       Writing State-of-the-Art TSRs that Exploit MS-DOS 5", Microsoft
  888.       Systems Journal, Jan-Feb 1992, Volume 7, Number 1, pages 41-59,
  889.       with examples downloadable in
  890.           pd1:<msdos.msjournal>msjv7-1.zip at Simtel
  891.  
  892.     - code for Al Stevens's "Writing Terminate-and-Stay-Resident
  893.       Programs", Computer Language, February 1988, pages 37-48 and March
  894.       1988, pages 67-76 is downloadable as
  895.         pd1:<msdos.c>tsrc.zip at Simtel
  896.  
  897.     - software examples to accompany Kaare Christian's "Using Microsoft
  898.       C Version 5.1 to Write Terminate-and-Stay-Resident Programs",
  899.       Microsoft Systems Journal, September 1988, Volume 3, Number 5,
  900.       pages 47-57 are downloadable as
  901.           pd1:<msdos.msjournal>msjv3-5.arc at Simtel
  902.  
  903.     Finally, there are commercial products, of which TesSeRact (for
  904.     C-language TSRs) is one of the best known.
  905.  
  906. Q708. How can I write a device driver?
  907.  
  908.     Many books answer this in detail.  Among them are {Advanced MS-DOS}
  909.     and {DOS 5: A Developer's Guide}, cited in the preceding Q.
  910.     Michael Tischer's {PC System Programming}, ISBN 1-55755-036-0, has
  911.     an extensive treatment, as does Dettman and Kyle's {DOS Programmer's
  912.     Reference: 2d Edition}, ISBN 0-88022-458-4.  For a really in-depth
  913.     treatment, look for a specialized book like Robert Lai's {Writing
  914.     MS-DOS Device Drivers}, ISBN 0-201-13185-4.
  915.  
  916. Q709. What can I use to manage versions of software?
  917.  
  918.     (rev: 18 Apr 1993)  A port of the Unix RCS utility is downloadable
  919.     from Simtel as pd1:<msdos.gnuish>rcs55ax.zip (EXE and docs) and
  920.     rcs55as.zip (source).  I haven't used it myself, but I understand
  921.     this is no longer limited to one-character extensions on filenames
  922.     (so .CPP and .BAS are fine).
  923.  
  924. Q710. What's this "null pointer assignment" after my C program executes?
  925.  
  926.     (rev: 18 Apr 1993)  Somewhere in your program, you assigned a value
  927.     _through_ a pointer without first assigning a value _to_ the
  928.     pointer.  (This might have been something like a strcpy or memcpy
  929.     with a pointer as its first argument, not necessarily an actual
  930.     assignment statement.) Your program may look like it ran correctly,
  931.     but if you get this message you can be certain that there's a bug
  932.     somewhere.
  933.  
  934.     Microsoft and Borland C, as part of their exit code (after a return
  935.     from your main function), check whether the location 0000 in your
  936.     data segment contains a different value from what you started with;
  937.     if so, they infer that you must have used an uninitialized pointer.
  938.  
  939.     To track down the problem, you can put exit( ) statements at various
  940.     spots in the program and narrow down where the uninitialized pointer
  941.     is being used by seeing which added exit( ) makes the null-pointer
  942.     message disappear.  Or, in the debugger, set a watch at location
  943.     0000 in your data segment, assuming you're in small or medium model.
  944.     (If data pointers are 32 bits, as in the compact and large models, a
  945.     null pointer will overwrite the interrupt vectors at 0000:0000 and
  946.     probably lock up your machine.)
  947.  
  948.     Under MSC/C++ 7.0, you can declare the undocumented library function
  949.  
  950.         extern _cdecl _nullcheck(void);
  951.  
  952.     and then sprinkle calls to _nullcheck( ) through your program at
  953.     regular intervals.
  954.  
  955.     Borland's TechFax document #TI726 discusses the null pointer
  956.     assignment from a Borland point of view.  It's one of many documents
  957.     downloadable as part of
  958.         pd1:<msdos.turbo-c>bchelp10.zip at Simtel
  959.         /pc/turbopas/bchelp10.zip at garbo.
  960.  
  961. Q711. How can my program tell if it's running under Windows?
  962.  
  963.     (rev: 18 Apr 1993)  Set AX=4680 and execute INT 2F.  If AX contains
  964.     0, you're in Windows real mode or standard mode (or under the DOS
  965.     5.0 shell).  Otherwise, set AX=1600 and INT 2F.  If AL does not
  966.     contain 0 or 80, you're in Windows 386 enhanced mode.  See {PC
  967.     Magazine} 24 Nov 1992 (xi:20), pages 492-493.
  968.  
  969.     When Windows 3.0 or 3.1 is running, the DOS environment will contain
  970.     a definition of the string windir, in lower case.
  971.  
  972.     For more information, see {PC Magazine} 26 May 1992 (xi:10) pages
  973.     345-346.  A program, WINMODE, is available as part of
  974.         pd1:<msdos.pcmag>vol11n10.zip at Simtel
  975.         /pc/pcmag/vol11n10.zip at garbo.
  976.  
  977. Q712. How do I copyright software that I write?
  978.  
  979.     (new: 5 Apr 1993) The following is adapted (and greatly condensed)
  980.     from chapter 4 of the Chicago Manual of Style (13th edition, ISBN
  981.     0-226-10390-0).  Disclaimer:  I am not a lawyer, and this is not
  982.     legal advice.  Also, there are very likely to be differences in
  983.     copyright law among nations.  No matter where you live, if
  984.     significant money may be involved, get legal advice.
  985.  
  986.     That said, in the U.S. (at least), when you write something, you own
  987.     the copyright.  (The most significant exception to programmers is
  988.     "works made for hire", i.e., something you write because your
  989.     employer or client pays you to.  A contract, agreed in advance, can
  990.     vest the copyright in the programmer even if an employee.)  You
  991.     don't have to register the work with the Copyright Office unless
  992.     (until) the copyright is infringed and you intend to bring suit;
  993.     however, it is easier to recover damages in court if you did
  994.     register the work within three months of publication.
  995.  
  996.     From paragraph 4.16 of the Chicago Manual:  "... the [copyright]
  997.     notice consists of three parts: (1) the symbol [C-in-a-circle]
  998.     (preferred because it also suits the requirements of the Universal
  999.     Copyright Convention), the word 'Copyright', or the abbreviation
  1000.     'Copr.', (2) a date--the year of first publication, and (3) the name
  1001.     of the copyright owner.  Most publishers also add the phrase 'All
  1002.     rights reserved' because it affords some protection in Central and
  1003.     South American countries ...."  Surprise:  "(C)" is legally not the
  1004.     same as the C-in-a-circle, so those of us who are ASCII-bound must
  1005.     use the word or the abbreviation.
  1006.  
  1007.  
  1008. (continued in part 4)
  1009.  
  1010. -- 
  1011. Stan Brown, Oak Road Systems                    brown@Ncoast.ORG
  1012.  
  1013. Can't find FAQ lists?  ftp to 'rtfm.mit.edu' and look in /pub/usenet
  1014. (or email me >>> with valid reply-to address <<< for instructions).
  1015.